package com.zzy.ymcc;

import com.zzy.ymcc.doc.CourseDoc;
import com.zzy.ymcc.repostry.CourseEsRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SearchApp.class)
public class es {

    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;


    @Autowired
    private CourseEsRepository courseEsRepository;

    @Test
    public void testCreat() throws Exception{
        // 根据doc索引对象穿件索引库
        elasticsearchRestTemplate.createIndex(CourseDoc.class);
        // 给索引库添加字段，添加映射
        elasticsearchRestTemplate.getMapping(CourseDoc.class);



    }

        @Test
    public void testCrud() throws Exception{
        CourseDoc courseDoc = new CourseDoc();
        courseDoc.setId(1L);
//        courseDoc.setCourseName("java高级课程");
        courseDoc.setGradeName("钻石");
        courseEsRepository.save(courseDoc);

        System.out.println(courseEsRepository.findById(1L));

        courseEsRepository.deleteById(1L);
        System.out.println(courseEsRepository.findById(1L));
    }

}
